import type { Nullable } from '@vben/types';

import type { BasicQueryParams, BasicResult, PaginationResult } from '../core';

import { requestClient } from '../request';

export namespace ApiKeyApi {
  const URL = '/auth/api_key';
  /** 用户组返回值 */
  export interface ApiKeyResult extends BasicResult {
    client: string;
    prefix: string;
    expire_at: Nullable<string>;
    is_expired: boolean;
  }

  /**
   * 查询用户组
   */
  export async function listApiKey(params: BasicQueryParams) {
    return requestClient.get<PaginationResult<ApiKeyResult>>(URL, {
      params,
      withCredentials: true,
    });
  }

  /**
   * 获取用户组
   */
  export async function retrieveApiKey(id: string) {
    return requestClient.get<ApiKeyResult>(`${URL}/${id}`, {
      withCredentials: true,
    });
  }
  /**
   * 创建用户组
   */
  export async function createApiKey(data: Partial<ApiKeyResult>) {
    return requestClient.post<string>(`${URL}`, data, {
      withCredentials: true,
    });
  }
  /**
   * 更新用户组
   */
  export async function updateApiKey(id: string, data: Partial<ApiKeyResult>) {
    return requestClient.patch<ApiKeyResult>(`${URL}/${id}`, data, {
      withCredentials: true,
    });
  }
  /**
   * 删除用户组
   */
  export async function deleteApiKey(id: string) {
    return requestClient.delete<any>(`${URL}/${id}`, {
      withCredentials: true,
    });
  }
}
